import java.util.ArrayList;

public class leetcode_704二分查找 {
    public static void main(String[] args) {
        System.out.println("hello");
        leetcode_704二分查找 l = new leetcode_704二分查找();
        int[] nums = {-1,0,3,5,9,12};
        System.out.println(l.search(nums, 9));
    }

    public int search(int[] nums, int target) {
        int left = 0;
        int right = nums.length - 1;
        while (left <= right) {
            int mid = left + (right - left) / 2;
            int n = nums[mid];
            if (n == target) {
                return mid;
            } else if (target < n) {
                right = mid - 1;
            } else if (target > n) {
                left = mid + 1;
            }
        }
        return -1;
    }
}
